<script type="text/javascript">
var errors=false;
function check(input)
{
		var div='#'+input+'Info';
		var ele = '#'+input;
		ele=$(ele);
		if (ele.val().length<2)
		{
			if ($(div).length<=0)  //questo metodo controlla l'esistenza del div
			{
				$('#ricerca').append('<div id="'+input+'Info" class="info"></div>');
				var typeInfo = $('#'+input+'Info');
				var pos = ele.offset();
				typeInfo.css({
					top: pos.top-3,
				left: pos.left+ele.width()+15
				});
				typeInfo.removeClass('correct').addClass('error').html('&larr; Inserire almeno 2 caratteri').fadeIn();
				ele.removeClass('normal').addClass('wrong');				
			}
			
		}
		else
		{		
		  var typeInfo = $('#'+input+'Info');
			var pos = ele.offset();
			typeInfo.css({
			top: pos.top-3,
			left: pos.left+ele.width()+15
			});
		if( ele.val().length<3) {
			  typeInfo.removeClass('correct').addClass('error').html('&larr; Inserire almeno 2 caratteri').show();
				ele.removeClass('normal').addClass('wrong');	
		} else{
				typeInfo.removeClass('error').addClass('correct').html('&radic;').show();
				ele.removeClass('wrong').addClass('normal');
				errors=true;
		} 
		}
}	
	
function sostituisciSpazio(stringa)
{
	var parts = stringa.split(' '),
            len = parts.length,i;
			var ind='';
        	for(i = 0; i < len-1; i += 1) {
            	ind += parts[i]+'%20';
        	} 
		    ind+=parts[len-1];
			return ind;
}


$('#button').click(function (){
		errors=false;
		check('nickname');
		check('password');
		check('nome');
		check('cognome');
		var id=$('select option:selected').val();
		if(errors) {
			var jrole = "utenti/visualizza.php";
			var data="nickname='"+sostituisciSpazio($('#nickname').val())+"'&password='"+sostituisciSpazio($('#password').val());
			data=data+"'&nome='"+sostituisciSpazio($('#nome').val());
			data=data+"'&cognome='"+sostituisciSpazio($('#cognome').val());
			data=data+"'&idgrado="+id;
			jrole=jrole+"?"+data;
			$('#ricerca').fadeOut(1000,function(){$('#ricerca').load(jrole,'',$('#ricerca').fadeIn(1000))});
			return false;
		}
	return false;
});


// ======================================================  //
</script>


<?php require_once('../Connections/mlu.php'); 
 
  $query_Recordset1 = "SELECT * FROM gradi";
  $Recordset1 = mysql_query($query_Recordset1, $mlu) or die(mysql_error());
  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Nickname:</td>
      <td><input type="text" name="nickname" value="" size="32" onkeyup="check(this.id);" id="nickname"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Password:</td>
      <td><input type="text" name="password" value="" size="32" onkeyup="check(this.id);" id="password"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Nome:</td>
      <td><input type="text" name="nome" value="" size="32" onkeyup="check(this.id);" id="nome"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Cognome:</td>
      <td><input type="text" name="cognome" value="" size="32" onkeyup="check(this.id);" id="cognome"/></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Idgrado:</td>
      <td><select name="idgrado">
        <?php 
do {  
?>
        <option value="<?php echo $row_Recordset1['idgrado']?>" ><?php echo $row_Recordset1['typegrado']?></option>
        <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
?>
      </select></td>
    </tr>
    <tr> </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><button id="button">Inserisci Record</button></td>
    </tr>
  </table>
